home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / falcon / programm.ing / nt_dsp1.lzh / NT_DSP1.MSA / FFT / FFTR2C.ASM < prev    next >
Assembly Source File  |  1990-01-17  |  6KB  |  150 lines

  1. ;
  2. ; This program originally available on the Motorola DSP bulletin board.
  3. ; It is provided under a DISCLAMER OF WARRANTY available from
  4. ; Motorola DSP Operation, 6501 Wm. Cannon Drive W., Austin, Tx., 78735.
  5. ; Radix 2, In-Place, Decimation-In-Time FFT (fast).
  6. ; Last Update 04 Feb 87   Version 1.2
  7. ;
  8. fftr2c  macro   points,data,coef
  9. fftr2c  ident   1,2
  10. ;
  11. ; Radix 2 Decimation in Time In-Place Fast Fourier Transform Routine
  12. ;
  13. ;    Complex input and output data
  14. ;        Real data in X memory
  15. ;        Imaginary data in Y memory
  16. ;    Normally ordered input data
  17. ;    Bit reversed output data
  18. ;       Coefficient lookup table
  19. ;        -Cosine values in X memory
  20. ;        -Sine values in Y memory
  21. ;
  22. ; Macro Call - fftr2c   points,data,coef
  23. ;
  24. ;       points     number of points (16-32768, power of 2)
  25. ;       data       start of data buffer
  26. ;       coef       start of sine/cosine table
  27. ;
  28. ; Alters Data ALU Registers
  29. ;       x1      x0      y1      y0
  30. ;       a2      a1      a0      a
  31. ;       b2      b1      b0      b
  32. ;
  33. ; Alters Address Registers
  34. ;       r0      n0      m0
  35. ;       r1      n1      m1
  36. ;               n2
  37. ;
  38. ;       r4      n4      m4
  39. ;       r5      n5      m5
  40. ;       r6      n6      m6
  41. ;
  42. ; Alters Program Control Registers
  43. ;       pc      sr
  44. ;
  45. ; Uses 6 locations on System Stack
  46. ;
  47. ; Latest Revision -  4-Feb-87
  48. ;
  49.         move    #data,r0        ;initialize input pointer
  50.         move    #points/4,n0    ;initialize butterflies per group
  51.         move    n0,n4           ;initialize pointer offsets
  52.         move    n0,n6           ;initialize coefficient offset
  53.         move    #points-1,m0    ;initialize address modifiers
  54.         move    m0,m1           ;for modulo(points) addressing
  55.         move    m0,m4
  56.         move    m0,m5
  57. ;
  58. ; Do first and second Radix 2 FFT passes
  59. ;
  60.         move            x:(r0)+n0,x0
  61.         tfr     x0,a    x:(r0)+n0,y1
  62.  
  63.         do      n0,_twopass
  64.         tfr     y1,b    x:(r0)+n0,y0
  65.         add     y0,a    x:(r0),x1                       ;ar+cr
  66.         add     x1,b    r0,r4                           ;br+dr
  67.         add     a,b     (r0)+n0                         ;ar'=(ar+cr)+(br+dr)
  68.         subl    b,a     b,x:(r0)+n0                     ;br'=(ar+cr)-(br+dr)
  69.         tfr     x0,a    a,x0            y:(r0),b
  70.         sub     y0,a                    y:(r4)+n4,y0    ;ar-cr
  71.         sub     y0,b    x0,x:(r0)                       ;bi-di
  72.         add     a,b                     y:(r0)+n0,x0    ;cr'=(ar-cr)+(bi-di)
  73.         subl    b,a     b,x:(r0)                        ;dr'=(ar-cr)-(bi-di)
  74.         tfr     x0,a    a,x0            y:(r4),b
  75.         add     y0,a                    y:(r0)+n0,y0    ;bi+di
  76.         add     y0,b    x0,x:(r0)+n0                    ;ai+ci
  77.         add     b,a                     y:(r0)+,x0      ;ai'=(ai+ci)+(bi+di)
  78.         subl    a,b                     a,y:(r4)+n4     ;bi'=(ai+ci)-(bi+di)
  79.         tfr     x0,a                    b,y:(r4)+n4
  80.         sub     y0,a    x1,b                            ;ai-ci
  81.         sub     y1,b    x:(r0)+n0,x0                    ;dr-br
  82.         add     a,b     x:(r0)+n0,y1                    ;ci'=(ai-ci)+(dr-br)
  83.         subl    b,a                     b,y:(r4)+n4     ;di'=(ai-ci)-(dr-br)
  84.         tfr     x0,a                    a,y:(r4)+
  85. _twopass
  86. ;
  87. ; Do all FFT passes but first, second and last pass
  88. ;
  89.         move    #points/8,n0    ;initialize butterflies per group
  90.         move    #4,n2           ;initialize groups per pass
  91.         move    #0,m6           ;initialize coefficient address modifier
  92.                                 ;for reverse carry (bit reversed) addressing
  93.  
  94.         do      #@cvi(@log(points)/@log(2)-2.5),_end_pass
  95.         move    #data,r0                ;initialize A input pointer
  96.         move    r0,r4                   ;initialize A output pointer
  97.         lua     (r0)+n0,r1      ;initialize B input pointer
  98.         move    #coef,r6        ;initialize C input pointer
  99.         lua     (r1)-,r5        ;initialize B output pointer
  100.         move    n0,n1           ;initialize pointer offsets
  101.         move    n0,n4
  102.         move    n0,n5
  103.  
  104.         do      n2,_end_grp
  105.         move    x:(r1),x1       y:(r6),y0       ;lookup -sine value
  106.         move    x:(r5),a        y:(r0),b
  107.         move    x:(r6)+n6,x0            ;lookup -cosine value
  108.  
  109.  
  110.         do      n0,_end_bfy    ;Radix 2 DIT butterfly kernel with constant
  111.         mac     x1,y0,b                         y:(r1)+,y1    ;twiddle factor
  112.         macr    -x0,y1,b        a,x:(r5)+       y:(r0),a
  113.         subl    b,a             x:(r0),b        b,y:(r4)
  114.         mac     -x1,x0,b        x:(r0)+,a       a,y:(r5)
  115.         macr    -y1,y0,b        x:(r1),x1
  116.         subl    b,a             b,x:(r4)+       y:(r0),b
  117. _end_bfy
  118.         move    a,x:(r5)+n5     y:(r1)+n1,y1    ;dummy load of x1 and y1
  119.         move    x:(r0)+n0,x1    y:(r4)+n4,y1
  120. _end_grp
  121.         move    n0,b1
  122.         lsr     b       n2,a1   ;divide butterflies per group by two
  123.         lsl     a       b1,n0   ;multiply groups per pass by two
  124.         move            a1,n2
  125. _end_pass
  126. ;
  127. ; Do last FFT pass
  128. ;
  129.         move    n1,n0           ;correct pointer offset for last pass
  130.         move    #data,r0        ;initialize A input pointer
  131.         move    r0,r4           ;initialize A output pointer
  132.         lua     (r0)+,r1        ;initialize B input pointer
  133.         move    #coef,r6        ;initialize C input pointer
  134.         lua     (r1)-n1,r5      ;initialize B output pointer
  135.         move    x:(r1),x1       y:(r6),y0
  136.         move    x:(r5),a        y:(r0),b
  137.  
  138.         do      n2,_lastpass    ;Radix 2 DIT butterfly kernel with one
  139.         mac     x1,y0,b x:(r6)+n6,x0    y:(r1)+n1,y1    ;butterfly per group
  140.         macr    -x0,y1,b        a,x:(r5)+n5     y:(r0),a
  141.         subl    b,a     x:(r0),b        b,y:(r4)
  142.         mac     -x1,x0,b        x:(r0)+n0,a     a,y:(r5)
  143.         macr    -y1,y0,b        x:(r1),x1       y:(r6),y0
  144.         subl    b,a             b,x:(r4)+n4     y:(r0),b
  145. _lastpass
  146.         move    a,x:(r5)+n5
  147.         endm
  148.